from  random import  randint
bank={"12345678": {"姓名": "张三", "密码": "123456","地址":"昌平","余额": 100, "开户行": "中信银行"},
      "87654321": {"姓名": "李四", "密码": "123456","地址":"昌平","余额": 100, "开户行": "工商银行"}}
bank_name="中信银行"

def useradd():
    account=randint(10000000,99999999)
    username=input("请输入您的用户名")
    password=input("请输入您的密码")
    country=input("\t\t请输入您的国家")
    province=input("\t\t请输入您的省份")
    street=input("\t\t请输入您的街道")
    door=input("\t\t请输入您的门牌号")
    ssr=bankadd(account,username,password,country,province,street,door,)
    if ssr==1:
        print("添加用户成功，以下是您的详细信息")
        info='''
            --------开户信息------
                账号:%s
                用户名:%s
                密码:******
                国家:%s
                省份:%s
                街道:%s
                门牌号:%s
                金额:%s
                开户行:%s
        '''
        print( info %(account,username,country,province,street,door,bank[username]["money"],bank_name))
    elif ssr == 2:
        print("用户名已存在")
    elif ssr ==3:
        print("数据库已满")

def bankadd(account,username,password,country,province,street,door):
    if  username in bank:
        return 2
    elif len(bank)>=100:
        return 3
    else:
        bank[username]={
            "account":account,
            "password":password,
            "country":country,
            "province":province,
            "street":street,
            "door":door,
            "money":0,
            "bank_name":bank_name
        }
        return 1

def saving():
    a=input("请输入您的账号")
    b=input("请输入您的密码")
    m=int(input("请输入您要存入的金额："))
    if a in bank:
        if b==bank[a]["密码"]:
            bank[a]["余额"]=bank[a]["余额"]+m
            bank.update({"余额": bank[a]["余额"]})
            print("您的账户当前余额为：" ,bank[a]["余额"])
        else:
            print("账户或密码错误")
            return False
    else:
        print("账户或密码错误")
        return False

def qq():
    a=input("请输入您的账号")
    b=input("请输入您的密码")
    c=int(input("请输入您要取出的金额："))
    if a in bank:
        if b==bank[a]["密码"] :
            if bank[a]["余额"]-c>=0:
                bank[a]["余额"]=bank[a]["余额"]-c
                bank.update({"余额": bank[a]["余额"]})
                print("您的账户当前余额为",bank[a]["余额"])
            else:
                print("您的余额不足")
                return 3
        else:
            print("账户或密码错误")
            return  2
    else:
        print("账户或密码错误")
        return 1

def zz():
    a = input("请输入您要转出的账号")
    b = input("请输入您要转入的账号")
    c = input("请输入您转出账户的密码")
    d = int(input("请输入您要转账的金额："))
    if a and b in bank:
        if c==bank[a]["密码"]:
            if bank[a]["余额"]-d>=0:
                bank[a]["余额"]=bank[a]["余额"] - d
                bank[b]["余额"]=bank[b]["余额"] + d
                bank.update({"余额": bank[a]["余额"]})
                bank.update({"余额": bank[b]["余额"]})
                print("转账成功，您当前账户余额为：",bank[a]["余额"])
            else:
                print("您的余额不足")
                return 3
        else:
            print("账户或密码错误")
            return 2
    else:
        print()
        return 1

def cx():
    a=input("请输入您的账号")
    b=input("请输入您的密码")
    if a in bank:
        if b==bank[a]["密码"]:
            print("当前账号:",a,
                  "密码:","XXXXXX",
                  "余额：",bank[a]["余额"],
                  "用户居住地址：",bank[a]["地址"],
                  "开户行：",bank[a]["开户行"])
        else:
            print("账号或密码错误")
    else:
        print("账号或密码错误")

print("=====================")
print(" 1.开户")
print(" 2.存钱")
print(" 3.取钱")
print(" 4.转账")
print(" 5.查询账户功能")
print(" 6.Bye!")
print("=====================")
o=input("请选择一个业务")
if o =="1":
    print("开户")
    useradd()
elif o=="2":
    print("存钱")
    saving()
elif o=="3":
    print("取钱")
    qq()
elif o=="4":
    print("转账")
    zz()
elif o=="5":
    cx()
elif o=="6":
    print("Bye!")

